package pub.wkq.user.service.impl;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pub.wkq.bo.ModifyUserBO;
import pub.wkq.common.exception.CustomException;
import pub.wkq.common.result.ResponseStatusEnum;
import pub.wkq.pojo.Users;
import pub.wkq.user.mapper.UsersMapper;
import pub.wkq.user.service.UserService;
import pub.wkq.vo.UsersVO;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UsersMapper usersMapper;

    @Override
    @Transactional
    public void modify(ModifyUserBO modifyUserBO) {
        String userId = modifyUserBO.getUserId();
        if (userId == null) {
            throw new CustomException(ResponseStatusEnum.USER_INFO_UPDATED_ERROR);
        }
        Users users = new Users();
        BeanUtils.copyProperties(modifyUserBO, users);
        users.setId(userId);
        users.setUpdatedTime(LocalDateTime.now());
        usersMapper.updateById(users);
    }

    @Override
    public Users getById(String userId) {
        Users users = usersMapper.selectById(userId);
        return users;
    }
}
